Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: GitHub Usernames are Case Insensitive #241

Merged
merged 17 commits into from
Jun 26, 2019
Merged

Conversation

megan07
Copy link
Contributor

@megan07 megan07 commented Jun 14, 2019

Addressing #196 where GitHub usernames were being treated as case-sensitive in the diff.
Before fix:

Step 1 error: After applying this step, the plan was not empty:

        DIFF:

        DESTROY/CREATE: github_team_membership.test_team_membership
          etag:     "W/\"52d84b121c000efbcf03e7e877c4fbf7\"" => "<computed>"
          id:       "3289152:Mbang-github2" => "<computed>"
          role:     "member" => "member"
          team_id:  "3289152" => "3289152"
          username: "mbang-github2" => "Mbang-github2" (forces new resource)
Step 1 error: After applying this step, the plan was not empty:

        DIFF:

        DESTROY/CREATE: github_membership.test_org_membership
          etag:     "W/\"ef0b40d063d184967e965b7d8af83466\"" => "<computed>"
          id:       "mbang-github-acc-test:mbang-github2" => "<computed>"
          role:     "member" => "member"
          username: "mbang-github2" => "Mbang-github2" (forces new resource)
    Error: Provider produced inconsistent result after apply

        When applying changes to
        github_repository_collaborator.test_repo_collaborator, provider "github"
        produced an unexpected new value for was present, but now absent.

        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.

FAIL

After fix:

=== RUN   TestAccGithubTeamMembership_basic
--- PASS: TestAccGithubTeamMembership_basic (13.25s)
PASS
=== RUN   TestAccGithubMembership_basic
--- PASS: TestAccGithubMembership_basic (4.08s)
PASS
=== RUN   TestAccGithubRepositoryCollaborator_basic
--- PASS: TestAccGithubRepositoryCollaborator_basic (10.31s)
PASS

I also tested that if the user DOES update the casing in the GitHub UI, a terraform refresh will pick that up.

@ghost ghost added the size/M label Jun 14, 2019
@ghost ghost added size/L and removed size/M labels Jun 14, 2019
@megan07 megan07 requested a review from a team June 20, 2019 19:53
Copy link

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megan07 this looks good so far. I took a quick pass and left a couple of comments. I'll circle back later today.

github/resource_github_membership_test.go Outdated Show resolved Hide resolved
@@ -140,3 +162,18 @@ var testAccGithubMembershipConfig string = fmt.Sprintf(`
role = "member"
}
`, testCollaborator)

func testAccGithubMembershipConfig_caseInsensitive() string {
otherCase := []rune(testCollaborator)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get the intent right, you are modifying the collaborator username, by toggling the case of the first rune, to test case insensitivity functionality. Is that correct? If so what about changing the function signature to take in an input, and just pass the collaborator name with the expected case.

func testAccGithubMembershipConfig_caseInsensitive(memberName string) {
return fmt.Sprintf(`
  resource "github_membership" "test_org_membership" {
    username = "%s"
    role = "member"
  }
`, memberName)
}

This way in the acceptance test you can run two TestSteps:

Steps: []resource.TestStep{
			{
				Config: testAccGithubMembershipConfig_caseInsensitive(strings.ToUpper(testCollaborator)),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGithubMembershipExists("github_membership.test_org_membership", &membership),
				),
			},
			{
				Config: testAccGithubMembershipConfig_caseInsensitive(strings.ToLower(testCollaborator)),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGithubMembershipExists("github_membership.test_org_membership", &membership),
				),
			},
		},

github/resource_github_repository_collaborator.go Outdated Show resolved Hide resolved
Copy link

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megan07 I left a few comments for you, but this is otherwise good.

--- PASS: TestAccGithubMembership_basic (3.30s)
--- PASS: TestAccGithubMembership_caseInsensitive (2.84s)
--- PASS: TestAccGithubMembership_importBasic (2.79s)
--- PASS: TestAccGithubRepositoryCollaborator_basic (9.65s)
--- PASS: TestAccGithubRepositoryCollaborator_importBasic (9.17s)

github/resource_github_repository_collaborator.go Outdated Show resolved Hide resolved
github/resource_github_repository_collaborator.go Outdated Show resolved Hide resolved
@megan07 megan07 requested a review from nywilken June 24, 2019 18:52
Copy link
Contributor

@paultyng paultyng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but otherwise LGTM


"github.com/google/go-github/v25/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccGithubMembership_basic(t *testing.T) {
if testCollaborator == "" {
t.Skip("Skipping because length of `GITHUB_TEST_COLLABORATOR` is not set")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this is a copy/paste typo for the message


func testAccGithubMembershipTheSame(orig, other *github.Membership) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *orig.URL != *other.URL {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also test to make sure at least one isn't null/empty? or should two empties be equal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, for the intent of the test, two empties would be equal. I can't think of a time when this would be empty here, but if they were to both be empty, I think it means the case change didn't have an effect.

var otherMembership github.Membership

oc := []rune(testCollaborator)
if unicode.IsUpper(oc[0]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if its possible, but could 0 ever be a number or symbol in a username?

@megan07 megan07 requested a review from paultyng June 24, 2019 21:26
@megan07 megan07 merged commit efbf3f2 into master Jun 26, 2019
@megan07 megan07 deleted the f-username-case branch June 26, 2019 15:48
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
@kjolley-zainar
Copy link

I'm still seeing this:

% tf --version
Terraform v1.6.6
on darwin_amd64

% tf plan
...
# module.github.github_repository_collaborators.myenv will be updated in-place
  ~ resource "github_repository_collaborators" "myenv" {
        id             = "myenv"
      ~ invitation_ids = {} -> (known after apply)
        # (1 unchanged attribute hidden)

      - user {
          - permission = "pull" -> null
          - username   = "foo" -> null
        }
      - user {
          - permission = "pull" -> null
          - username   = "bar" -> null
        }
      + user {
          + permission = "pull"
          + username   = "Foo"
        }
      + user {
          + permission = "pull"
          + username   = "Bar"
        }

        # (4 unchanged blocks hidden)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants